package com.ytjj.qmyx.admin.service.impl;

import com.gexin.fastjson.JSON;
import com.gexin.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.ytjj.common.api.CommonPage;
import com.ytjj.common.api.CommonResult;
import com.ytjj.common.constants.DateUtils;
import com.ytjj.common.exception.ApiException;
import com.ytjj.common.utils.DateTimeUtil;
import com.ytjj.common.utils.HttpClientUtil;
import com.ytjj.qmyx.admin.config.SupplyApiConfig;
import com.ytjj.qmyx.admin.dao.OrderNoteDao;
import com.ytjj.qmyx.admin.dao.ReissueLogisticsDao;
import com.ytjj.qmyx.admin.dao.ReissueLogisticsNoteDao;
import com.ytjj.qmyx.admin.eunm.ReissueTypeEnums;
import com.ytjj.qmyx.admin.mapper.ReissueHistoryMapper;
import com.ytjj.qmyx.admin.mapper.UpdateProductSpecRecordMapper;
import com.ytjj.qmyx.admin.model.ReissueHistory;
import com.ytjj.qmyx.admin.model.UpdateProductSpecRecord;
import com.ytjj.qmyx.admin.model.request.*;
import com.ytjj.qmyx.admin.model.response.ReissueHistoryResponse;
import com.ytjj.qmyx.admin.model.response.ReissueLogisticsExportResponse;
import com.ytjj.qmyx.admin.model.response.ReissueLogisticsResponse;
import com.ytjj.qmyx.admin.service.CustomerService;
import com.ytjj.qmyx.admin.service.MemberService;
import com.ytjj.qmyx.admin.service.ReissueLogisticsService;
import com.ytjj.qmyx.mall.mapper.OrdersInfoMapper;
import com.ytjj.qmyx.mall.mapper.ProductMapper;
import com.ytjj.qmyx.mall.mapper.ReissueLogisticsMapper;
import com.ytjj.qmyx.mall.model.*;
import com.ytjj.qmyx.mall.model.BankerRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Service
@Slf4j
public class ReissueLogisticsServiceImpl implements ReissueLogisticsService {

    @Autowired
    private ReissueLogisticsDao reissueLogisticsDao;

    @Autowired
    private MemberService memberService;

    @Autowired
    private OrderNoteDao orderNoteDao;

    @Resource
    private ReissueLogisticsMapper reissueLogisticsMapper;

    @Resource
    private ReissueLogisticsNoteDao reissueLogisticsNoteDao;

    @Autowired
    private CustomerService customerService;

    @Resource
    private SupplyApiConfig supplyApiConfig;

    @Resource
    private OrdersInfoMapper ordersInfoMapper;

    @Resource
    private ProductMapper productMapper;

    @Resource
    private ReissueHistoryMapper reissueHistoryMapper;

    @Resource
    private UpdateProductSpecRecordMapper updateProductSpecRecordMapper;

    @Override
    public CommonPage<ReissueLogisticsResponse> getReissueLogisticsList(LogisticsRequest logisticsRequest) {

        if (StringUtils.isNotBlank(logisticsRequest.getBuyer())){
            BankerRequest request1 = new BankerRequest();
            request1.setBuyer(logisticsRequest.getBuyer());
            String json1 = com.alibaba.fastjson.JSON.toJSONString(request1);
            String result = HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/banker/getBankerIdsByBankerMsg", json1, supplyApiConfig.getHeadsMap());
            List<Integer> bankerIds = com.alibaba.fastjson.JSONObject.parseArray(result, Integer.class);
            if (CollectionUtils.isEmpty(bankerIds)){
                return CommonPage.restPage(new ArrayList<>());
            }
            logisticsRequest.setBankerIds(bankerIds);
        }


        PageHelper.startPage(logisticsRequest.getPageNum(), logisticsRequest.getPageSize());
//        if (logisticsRequest.getDayTime() != null) {
//            String sTime = logisticsRequest.getDayTime() + " 00:00:00";
//            String eTime = logisticsRequest.getDayTime() + " 23:59:59";
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            try {
//                Date startTime = sdf.parse(sTime);
//                Date endTime = sdf.parse(eTime);
//                logisticsRequest.setStartTime(startTime);
//                logisticsRequest.setEndTime(endTime);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }

        List<ReissueLogisticsResponse> pageList = reissueLogisticsDao.getReissueLogisticsList(logisticsRequest);
        if(!CollectionUtils.isEmpty(pageList)) {
            List<String> childOrderNoList = pageList.stream().filter(item -> !StringUtils.isEmpty(item.getChildOrderNo())).map(ReissueLogisticsResponse::getChildOrderNo).collect(Collectors.toList());
            List<ReissueLogistics> reissueLogistics = null;
            if (!CollectionUtils.isEmpty(childOrderNoList)) {
                reissueLogistics = reissueLogisticsDao.selectByChildOrderNoList(childOrderNoList);
            }
            List<ReissueHistoryResponse> histories = reissueHistoryMapper.queryHistory(childOrderNoList);

            List<Integer> productIdList = pageList.stream().filter(item -> null != item.getProductId()).map(ReissueLogisticsResponse::getProductId).collect(Collectors.toList());
            List<Product> products = null;
            if (!CollectionUtils.isEmpty(productIdList)) {
                ProductExample example = new ProductExample();
                example.createCriteria().andIdIn(productIdList);
                products = productMapper.selectByExample(example);
            }


            List<Integer> bankerIds = pageList.stream().map(ReissueLogisticsResponse::getBankerId).collect(Collectors.toList());
            List<BankerResponse> bankerResponses = customerService.getBankerResponses(bankerIds);
            for (ReissueLogisticsResponse rle : pageList) {
                String notes = "";
                List<ReissueLogisticsNote> list = reissueLogisticsNoteDao.selectList(rle.getId());
                if (!CollectionUtils.isEmpty(list)) {
                    for (ReissueLogisticsNote  rln : list) {
                        notes += " // " + rln.getContent();
                    }
                }

                //图片视频转换List
                if(rle.getImage() != null) {
                    String imageUrl = rle.getImage();
                    String[] imageArray = imageUrl.split(",");
                    List<Map<String, String>> imageList = new ArrayList<>();
                    for(String img : imageArray) {
                        Map<String, String> map = new HashMap<>();
                        map.put("img", img);
                        imageList.add(map);
                    }
                    rle.setImageList(imageList);
                }

                rle.setNotes(notes);


                //采购员
                List<BankerResponse> bankers = bankerResponses.stream().filter(item -> rle.getBankerId().equals(item.getBankerId())).collect(Collectors.toList());
                if (!CollectionUtils.isEmpty(bankers)){
                    rle.setBuyer(bankers.get(0).getBuyer());
                }
                if (!com.alibaba.excel.util.CollectionUtils.isEmpty(reissueLogistics)) {
                    List<ReissueLogistics> reissueLogisticsList = reissueLogistics.stream().filter(item -> item.getChildOrderNo().equals(rle.getChildOrderNo())).collect(Collectors.toList());
                    rle.setReissueLogisticsCount(com.alibaba.excel.util.CollectionUtils.isEmpty(reissueLogisticsList) ? 0 : reissueLogisticsList.size());
                }

                if (!com.alibaba.excel.util.CollectionUtils.isEmpty(products)) {
                    List<Product> collect1 = products.stream().filter(item -> item.getId().equals(rle.getProductId())).collect(Collectors.toList());
                    rle.setSupplyProductId(com.alibaba.excel.util.CollectionUtils.isEmpty(collect1) ? 0 : collect1.get(0).getSupplyProductId());
                }
                if (!com.alibaba.excel.util.CollectionUtils.isEmpty(histories)) {
                    List<ReissueHistoryResponse> collect = histories.stream().filter(t1 -> t1.getChildOrderNo().equals(rle.getChildOrderNo())).collect(Collectors.toList());
                    rle.setHistories(collect);
                }
//                String statusDesc = rle.getLogisticsReceiptTime() == null ? rle.getStatusDesc() : DateTimeUtil.TimeToStr(rle.getLogisticsReceiptTime()) + "   " + rle.getStatusDesc();
//                rle.setStatusDesc(statusDesc);
                //原订单状态
            }
        }
        return CommonPage.restPage(pageList);
    }

    @Override
    public List<ReissueLogisticsExportResponse> exportList(LogisticsRequest logisticsRequest) {
        if (StringUtils.isNotBlank(logisticsRequest.getBuyer())){
            BankerRequest request1 = new BankerRequest();
            request1.setBuyer(logisticsRequest.getBuyer());
            String json1 = com.alibaba.fastjson.JSON.toJSONString(request1);
            String result = HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/banker/getBankerIdsByBankerMsg", json1, supplyApiConfig.getHeadsMap());
            List<Integer> bankerIds = com.alibaba.fastjson.JSONObject.parseArray(result, Integer.class);
            if (CollectionUtils.isEmpty(bankerIds)){
                return new ArrayList<>();
            }
            logisticsRequest.setBankerIds(bankerIds);
        }

        List<ReissueLogisticsExportResponse> reissueLogisticsList = reissueLogisticsDao.getReissueLogisticsExportList(logisticsRequest);
        if (!CollectionUtils.isEmpty(reissueLogisticsList)) {
            List<String> childOrderNoList = reissueLogisticsList.stream().filter(item -> !StringUtils.isEmpty(item.getChildOrderNo())).map(ReissueLogisticsExportResponse::getChildOrderNo).collect(Collectors.toList());
            List<ReissueLogistics> reissueLogistics = null;
            if (!CollectionUtils.isEmpty(childOrderNoList)) {
                reissueLogistics = reissueLogisticsDao.selectByChildOrderNoList(childOrderNoList);
            }
            for (ReissueLogisticsExportResponse response : reissueLogisticsList) {
                if (!com.alibaba.excel.util.CollectionUtils.isEmpty(reissueLogistics)) {
                List<ReissueLogistics> logistics = reissueLogistics.stream().filter(item -> item.getChildOrderNo().equals(response.getChildOrderNo())).collect(Collectors.toList());
                    response.setReissueLogisticsCount(com.alibaba.excel.util.CollectionUtils.isEmpty(logistics) ? 0 : logistics.size());
                }
            }

        }
        return reissueLogisticsList;
    }

    @Override
    public CommonResult insertLogistics(ReissueLogistics reissueLogistics) {
        OrdersInfo ordersInfo = ordersInfoMapper.selectByPrimaryKey(reissueLogistics.getOrderInfoId());
//        List<ReissueLogistics> list = reissueLogisticsDao.selectByChildOrderNo(ordersInfo.getChildOrderNo());
//        if (list.size() > 0){
//            return CommonResult.failed("该订单已经有补单数据");
//        }

        reissueLogistics.setAdminId(memberService.getAdmin().getId());
        reissueLogistics.setCreateName(memberService.getAdmin().getName());
        reissueLogistics.setStatus(0);
        reissueLogistics.setCreateTime(new Date());
        reissueLogistics.setOperationTime(new Date());
        if (StringUtils.isNotBlank(reissueLogistics.getRecoveryOrderNo())) {
            reissueLogistics.setAcquiringDay(new Date());
        } else {
            reissueLogistics.setAcquiringDay(null);
        }
        reissueLogistics.setOldOrderNo(reissueLogistics.getExpressNo());
        reissueLogistics.setExpressNo(null);
        reissueLogistics.setExpressCompanyNo(null);
        reissueLogistics.setFeedbackUrl(null);
        reissueLogistics.setChildOrderNo(ordersInfo.getChildOrderNo());
        reissueLogistics.setShopId(supplyApiConfig.getShopId());
        reissueLogistics.setRefuseReason(null);
        reissueLogistics.setSupplementaryDay(null);
        reissueLogistics.setReissueStatus(1);
        reissueLogistics.setLogisticsReceiptTime(null);
        reissueLogistics.setExpressText(null);
        reissueLogistics.setExpressRecord(null);
        reissueLogistics.setStatusCode(null);
        reissueLogistics.setStatusDesc(null);
        Integer insert = reissueLogisticsDao.insertLogistics(reissueLogistics);
        reissueLogistics.setReissueLogisticsId(reissueLogistics.getId());

        //补单--增加同步小记
        OrderNote orderNote = new OrderNote();
        orderNote.setAdminId(memberService.getAdmin().getId());
        orderNote.setContent("该订单补单状态--待处理！");
        orderNote.setOrderInfoId(reissueLogistics.getOrderInfoId());
        orderNote.setCreateTime(new Date());
        orderNoteDao.insertOrderNote(orderNote);

        String json = HttpClientUtil.doPostJson(supplyApiConfig.getUrl() + "/order/insertLogistics",
                JSONObject.toJSONString(reissueLogistics), supplyApiConfig.getHeadsMap());

        CommonResult commonResult = JSONObject.parseObject(json, CommonResult.class);
        if (null == commonResult || 200 != commonResult.getCode()) {
            return commonResult;
        }
        return  insert> 0 ? CommonResult.success() : CommonResult.failed();
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public CommonResult updateRetrieveInfo(ReissueLogisticsRetrieveRequest reissueLogistics, Integer adminId) {
        ReissueLogistics logistics = reissueLogisticsMapper.selectByPrimaryKey(reissueLogistics.getId());
        if (logistics.getStatus() == 3) {
            throw  new ApiException("补单失败的记录不能修改!");
        }
        Assert.notNull(reissueLogistics.getChildOrderNo(),"子订单不能为空！");
        int i = reissueLogisticsMapper.updateRecoveryOrderNo(reissueLogistics.getId(),StringUtils.isNotBlank(reissueLogistics.getRecoveryOrderNo()) ?
                reissueLogistics.getRecoveryOrderNo().trim() : null ,new Date(),
                2,reissueLogistics.getProductSkuSpec(),reissueLogistics.getUserAddress(),
                reissueLogistics.getUserName(),reissueLogistics.getUserPhone(),reissueLogistics.getDescr());

        if (StringUtils.isNotBlank(reissueLogistics.getRecoveryOrderNo())) {
            ReissueHistory reissueHistory = new  ReissueHistory();
            reissueHistory.setAdminId(adminId);
            reissueHistory.setCreateTime(new Date());
            reissueHistory.setReason("用户"+ adminId + "在"+DateTimeUtil.getTime() +"把快递单号改为 " + reissueLogistics.getRecoveryOrderNo());
            reissueHistory.setReissueLogisticsId(reissueLogistics.getId());
            reissueHistory.setChildOrderNo(reissueLogistics.getChildOrderNo());
            reissueHistory.setType(2);
            reissueHistoryMapper.insert(reissueHistory);
        }
        //保存修改记录
        if (!reissueLogistics.getProductSkuSpec().equals(logistics.getProductSkuSpec())) {
            UpdateProductSpecRecord record = new UpdateProductSpecRecord();
            record.setAdminId(adminId);
            record.setBeforeProductSkuSpec(logistics.getProductSkuSpec());
            record.setAfterProductSkuSpec(reissueLogistics.getProductSkuSpec());
            record.setCreateTime(new Date());
            record.setReissueLogisticsId(reissueLogistics.getId());
            record.setUpdateType(1);
            record.setOrderInfoId(null);
            updateProductSpecRecordMapper.insert(record);
        }

        if(i > 0){
            ReissueLogistics request = reissueLogisticsMapper.selectByPrimaryKey(reissueLogistics.getId());
            request.setShopId(supplyApiConfig.getShopId());
            request.setChildOrderNo(reissueLogistics.getChildOrderNo());
            request.setReissueLogisticsId(reissueLogistics.getId());
            request.setProductSkuSpec(reissueLogistics.getProductSkuSpec());
            request.setUserAddress(reissueLogistics.getUserAddress());
            request.setUserPhone(reissueLogistics.getUserPhone());
            request.setUserName(reissueLogistics.getUserName());
            request.setDescr(reissueLogistics.getDescr());
            String json = JSON.toJSONString(request);
            log.info("=========同步供应链补单信息====参数======reissueLogistics:{}",json);
            HttpClientUtil.doPostJson(supplyApiConfig.getUrl()+"/order/updateLogisticsDate", json,supplyApiConfig.getHeadsMap());
        }
        return CommonResult.success();
    }


    @Override
    public Integer updateStatus(Integer id) {
        Integer integer = reissueLogisticsDao.updateStatus(id, new Date());
        if (integer == 1) {
            ReissueLogistics reissueLogistics = reissueLogisticsMapper.selectByPrimaryKey(id);
            reissueLogistics.setShopId(supplyApiConfig.getShopId());
            String json = JSON.toJSONString(reissueLogistics);
            log.debug("=========同步供应链补单信息====参数======reissueLogistics:{}",json);
            HttpClientUtil.doPostJson(supplyApiConfig.getUrl()+"/order/updateLogistics", json,supplyApiConfig.getHeadsMap());
        }
        return integer;
    }

    @Override
    public void batchHandle(String ids) {
        String[] idStr = ids.split(",");
        List<String> idStrings = Arrays.asList(idStr);
        for (String id : idStrings) {
            ReissueLogistics reissueLogistics = reissueLogisticsMapper.selectByPrimaryKey(Integer.valueOf(id));
            if(reissueLogistics.getStatus() == 0) {
                reissueLogistics.setId(Integer.valueOf(id));
                reissueLogistics.setStatus(1);
                reissueLogistics.setOperationTime(new Date());
                reissueLogisticsMapper.updateByPrimaryKeySelective(reissueLogistics);

                reissueLogistics.setShopId(supplyApiConfig.getShopId());
                String json = JSON.toJSONString(reissueLogistics);
                HttpClientUtil.doPostJson(supplyApiConfig.getUrl() +"/order/updateLogistics", json, supplyApiConfig.getHeadsMap());
                continue;
            }
            throw new ApiException("订单已处理, 请检查后重试");
        }

    }

    @Override
    public Integer delReissueLogistics(LogisticsDeleteRequest request) {
        //删除供应链的补单数据
        ReissueLogistics reissueLogistics = reissueLogisticsMapper.selectByPrimaryKey(request.getId());
        Assert.isTrue(StringUtils.isBlank(reissueLogistics.getExpressNo()),"已补发的补单数据不能移除！");
        if (reissueLogistics.getStatus() == 3) {
            throw  new ApiException("补单失败的数据不能移除！");
        }

//        if (ReissueTypeEnums.REISSUE.getCode().equals(reissueLogistics.getReissueType())) {
            ReissueHistory reissueHistory = new  ReissueHistory();
            reissueHistory.setAdminId(request.getAdminId());
            reissueHistory.setCreateTime(new Date());
            reissueHistory.setReason(reissueHistory.getReason());
            reissueHistory.setReissueLogisticsId(reissueLogistics.getId());
            reissueHistory.setChildOrderNo(reissueLogistics.getChildOrderNo());
            reissueHistory.setType(1);
            reissueHistoryMapper.insert(reissueHistory);
//        }



        Map<String,String> map = new HashMap<>();
        map.put("childOrderNo",reissueLogistics.getChildOrderNo());
        map.put("reissueLogisticsId",request.getId().toString());
        log.debug("=========同步供应链补单信息====参数======getChildOrderNo:{},reissueLogisticsId:{}",reissueLogistics.getChildOrderNo(),request.getId());
        String s = HttpClientUtil.doGet(supplyApiConfig.getUrl() + "/order/deleteLogistics", map, supplyApiConfig.getHeadsMap());
        log.debug("=========同步供应链补单信息====返回======s:{}",s);
        return  reissueLogisticsDao.updateDeleteStatus(request.getId());
    }

    @Override
    public CommonPage<ReissueLogisticsResponse> exportData(LogisticsRequest logisticsRequest) {
        PageHelper.startPage(logisticsRequest.getPageNum(), logisticsRequest.getPageSize());
        if (logisticsRequest.getDayTime() != null) {
            String sTime = logisticsRequest.getDayTime() + " 00:00:00";
            String eTime = logisticsRequest.getDayTime() + " 23:59:59";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                Date startTime = sdf.parse(sTime);
                Date endTime = sdf.parse(eTime);
                logisticsRequest.setStartTime(startTime);
                logisticsRequest.setEndTime(endTime);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

        List<ReissueLogisticsResponse> pageList = reissueLogisticsDao.getReissueLogisticsList(logisticsRequest);
        if(!CollectionUtils.isEmpty(pageList)) {
            List<String> childOrderNoList = pageList.stream().filter(item -> !StringUtils.isEmpty(item.getChildOrderNo())).map(ReissueLogisticsResponse::getChildOrderNo).collect(Collectors.toList());
            List<ReissueLogistics> reissueLogistics = null;
            if (!CollectionUtils.isEmpty(childOrderNoList)) {
                reissueLogistics = reissueLogisticsDao.selectByChildOrderNoList(childOrderNoList);
            }

            List<Integer> productIdList = pageList.stream().filter(item -> null != item.getProductId()).map(ReissueLogisticsResponse::getProductId).collect(Collectors.toList());
            ProductExample example = new ProductExample();
            example.createCriteria().andIdIn(productIdList);
            List<Product> products = productMapper.selectByExample(example);

            for (ReissueLogisticsResponse rle : pageList) {
                String notes = "";
                List<ReissueLogisticsNote> list = reissueLogisticsNoteDao.selectList(rle.getId());
                if (!CollectionUtils.isEmpty(list)) {
                    for (ReissueLogisticsNote  rln : list) {
                        notes += " // " + rln.getContent();
                    }
                }
                rle.setNotes(notes);
                if (!com.alibaba.excel.util.CollectionUtils.isEmpty(reissueLogistics)) {
                    List<ReissueLogistics> reissueLogisticsList = reissueLogistics.stream().filter(item -> item.getChildOrderNo().equals(rle.getChildOrderNo())).collect(Collectors.toList());
                    rle.setReissueLogisticsCount(com.alibaba.excel.util.CollectionUtils.isEmpty(reissueLogisticsList) ? 0 : reissueLogisticsList.size());
                }
                //供应链商品id
                if (!com.alibaba.excel.util.CollectionUtils.isEmpty(products)) {
                    List<Product> collect1 = products.stream().filter(item -> item.getId().equals(rle.getProductId())).collect(Collectors.toList());
                    rle.setSupplyProductId(com.alibaba.excel.util.CollectionUtils.isEmpty(collect1) ? 0 : collect1.get(0).getSupplyProductId());
                }
//                String statusDesc = rle.getLogisticsReceiptTime() == null ? rle.getStatusDesc() : DateTimeUtil.TimeToStr(rle.getLogisticsReceiptTime()) + "   " + rle.getStatusDesc();
//                rle.setStatusDesc(statusDesc);
            }
        }

        //导出时将导出状态改为：已导出
        if(!CollectionUtils.isEmpty(pageList)) {
            for (ReissueLogisticsResponse res : pageList) {
                reissueLogisticsDao.updateExportStatus(res.getId());
            }
        }
        return CommonPage.restPage(pageList);
    }

    @Override
    public boolean updatefinishStatus(Integer id,Date finishTime) {
        return reissueLogisticsDao.updatefinishStatus(id,finishTime);
    }

    @Override
    public boolean updateSupplyChainFinishStatus(Integer id,String childOrderNo) {
        Map<String,String> map = new HashMap<>();
        map.put("finishStatus","1");
        map.put("reissueLogisticsId",id.toString());
        map.put("childOrderNo",childOrderNo);
        HttpClientUtil.doGet(supplyApiConfig.getUrl() + "/order/finishedReissueLogistics", map, supplyApiConfig.getHeadsMap());
        return false;
    }

    @Override
    public void finishedReissueLogistics(LogisticsFinishRequest logisticsFinishRequest) {
        ReissueLogistics reissueLogistics = reissueLogisticsDao.selectById(logisticsFinishRequest.getId());
        Assert.notNull(reissueLogistics,"查询补单记录失败!");
        if (logisticsFinishRequest.getFinishStatus().equals(0)) {
            reissueLogisticsDao.updateReissueLogisticsFished(logisticsFinishRequest.getId(),
                    logisticsFinishRequest.getFinishStatus(),StringUtils.isNoneBlank(reissueLogistics.getExpressNo()) ? 2: 1 ,null);
        } else {
            reissueLogisticsDao.updateReissueLogisticsFished(logisticsFinishRequest.getId(),
                    logisticsFinishRequest.getFinishStatus(),3 ,new Date());
        }

        Map<String,String> map = new HashMap<>();
        map.put("finishStatus",logisticsFinishRequest.getFinishStatus().toString());
        map.put("reissueLogisticsId",logisticsFinishRequest.getId().toString());
        HttpClientUtil.doGet(supplyApiConfig.getUrl() + "/order/finishedReissueLogistics", map, supplyApiConfig.getHeadsMap());

    }

    @Override
    public void updateSupplyChainLogisticsReason(Integer id, String logisticsReason,String childOrderNo) {
        Map<String,String> map = new HashMap<>();
        map.put("reissueLogisticsId",id.toString());
        map.put("logisticsReason",logisticsReason);
        map.put("childOrderNo",childOrderNo);
        HttpClientUtil.doGet(supplyApiConfig.getUrl() + "/order/updateLogisticsReason", map, supplyApiConfig.getHeadsMap());
    }
}
